﻿Imports TransportadoraToledoBLL
Imports System.Windows.Forms

Public Class frm_cadastro_permissao
    Public usu_codigo As Integer
    Public confirma As Boolean = False

    Private Sub bCancelar_Click(sender As System.Object, e As System.EventArgs) Handles bCancelar.Click
        confirma = False
        Me.Close()
    End Sub

    Private Sub frm_cadastro_permissao_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim objP As New UsuariosBLL
        Dim tab As New DataTable
        Dim cb As New CheckBox
        Try
            tab = objP.localizarPermissao(usu_codigo)
            'For Each obj As Control In gbCadastros.Controls
            '    cb = obj
            '    For Each linha As DataRow In tab.Rows
            '        If linha(2) = cb.Name.Substring(2) Then
            '            cb.Checked = True
            '        End If
            '    Next
            'Next
            For Each obj As Control In Me.Controls
                If obj.Name.Substring(0, 2) = "cb" Then
                    cb = obj
                    For Each linha As DataRow In tab.Rows
                        If linha(3) = cb.Tag Then
                            cb.Checked = True
                        End If
                    Next
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            confirma = False
            Me.Close()
        End Try
    End Sub

    Private Sub bConfirmar_Click(sender As System.Object, e As System.EventArgs) Handles bConfirmar.Click
        Dim objP As New UsuariosBLL
        Dim cb As New CheckBox
        Try
            objP.excluirPermissao(usu_codigo)
            'For Each obj As Control In gbCadastros.Controls
            '    cb = obj
            '    If cb.Checked Then
            '        objP.inserirPermissao(usu_codigo, obj.Name.Substring(2))
            '    End If
            'Next
            For Each obj As Control In Me.Controls
                If obj.Name.Substring(0, 2) = "cb" Then
                    cb = obj
                    If cb.Checked Then
                        objP.inserirPermissao(usu_codigo, Integer.Parse(obj.Tag))
                    End If
                End If
            Next
            confirma = True
            Me.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


End Class